Repository navigation
sim_encoder: fix negative velocity at the thread rate cap; spindle sims use sim_spindle - #4583
grandixximo wants to merge 2 commits into
Conversation
|
didn't try it, but LGTM. |
|
@DauntlessAq could you give it a test? |
|
On hold until 64-bit HAL merge. May need to change again. |
|
I think we should park this until after the 64-bit change. |
|
remove and replace with stepgen in velocity mode? |
|
Parked, agreed. I looked into sim_encoder against stepgen in velocity mode before answering. stepgen can't replace it: its quadrature output has A and B but no index, and these sims need the index for The replacement that fits is So after the 64-bit work I'd rework this PR: switch the six sims that use sim_encoder (gmoccapy mill, lathe and scara, |
eaa8738 to
c4b331e
Compare
|
@andypugh unparked now that the 64-bit work is in, and reworked as discussed: the gmoccapy mill and lathe sims and |
| /* export pin for speed cap indication */ | ||
| retval = hal_pin_new_bool(comp_id, HAL_OUT, &(addr->saturated), 0, | ||
| "%s.saturated", prefix); | ||
| if (retval != 0) { | ||
| return retval; | ||
| } |
| (unsigned long)hal_get_uint(sim_enc->ppr), periodns); | ||
| } | ||
| hal_set_bool(sim_enc->saturated, clamped); | ||
| sim_enc->addval = aval; | ||
| sim_enc++; | ||
| } |
The frequency generator add value is freq * 2^31/maxf, and make_pulses() uses bit 31 of addval as the direction bit. The old freq clamp at +/-maxf allowed addval to reach exactly +2^31, setting bit 31, so a commanded speed at or above the cap was misread as negative rotation: the simulated counts ran backwards and encoder.N.velocity went negative (e.g. at >= 12500 rpm with ppr 12 and a 100000 ns base thread). With a spindle-at-speed interlock this makes a program dwell forever. Clamp the add value magnitude to less than 2^31 instead, so the outputs now keep turning in the commanded direction at the maximum rate. Also add a 'saturated' output pin that is true while the cap is engaged, and print a one-shot warning naming the maximum supported speed.
The gmoccapy mill and lathe sims and lathe_multispindle simulated the spindle with sim_encoder pulses counted by the encoder component in the base thread. That count rate caps at 12500 rpm with the stock settings; above it speed-in went wrong, at-speed never came and G33 never started. sim_spindle gives position and index directly with no speed cap, as basic_sim.tcl already does for most sims. lathe_multispindle also put spindle 1's index-enable on encoder 0; each spindle now has its own. The scara spindle_sim.hal is removed: no INI loads it and it still used the old motion.spindle-* pins. Tested headless on the three configs: G33 at 1000 and 20000 rpm completes with the right speed-in; on master the 20000 rpm pass never starts.
c4b331e to
80bab25
Compare
Fixes #4582.
Root cause
sim_encoderruns its pulse generator in the base thread, so the quadrature count rate (rpm/60 × ppr × 4) cannot exceed the base thread frequency.update_speed()clamped the requested frequency at that limit (maxf), which makes the frequency-generator add value exactly +2^31.make_pulses()uses bit 31 ofaddvalas the direction bit, so any positive speed at or above the cap was misread as negative rotation: the simulated counts ran backwards andencoder.N.velocitywent negative (12500 rpm with the stock ppr 12 and a 100000 ns base period).spindle.0.at-speedthen never asserts and a program dwells forever.Changes
saturatedoutput pin that is true while the cap is engaged (suggested by @rmu75); print a one-shot warning naming the maximum supported speed; document the pin and the cap formula in the man page.lathe_multispindlenow simulate the spindle withsim_spindle, asbasic_sim.tcldoes, so they have no speed cap.lathe_multispindlealso gets its own index-enable per spindle (spindle 1 was on encoder 0). The scaraspindle_sim.halis removed: no INI loads it and it still used the oldmotion.spindle-*pins.panelui-demoandspartankeep sim_encoder: they simulate a parport machine whose encoder comes in on parport pins, so the quadrature signal is the point. With the fix they saturate at their cap instead of running backwards.Testing
saturatedtoggles correctly in both directions, warning fires once.lathe_multispindle).